﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Fcdbas.WinUI.Forms;

using Fcdbas.Platform.Interface;
using Fcdbas.WinUI.Common;
using Fcdbas.Core.Windows;
using Fcdbas.WinUI.Windows;
using Fcdbas.Platform.Properties;
using Fcdbas.Platform;
using Fcdbas.WinUI.Controls;
using Fcdbas.Core;

namespace Fcdbas.WinUI.Forms
{
    public partial class dlgAskFetch : cDialogWindow
    {
        private int RecordCount;
        private DataSourceBinding Dsb = null;
        private BaseForm ParentForm;
        private string Msg = "总共有 {0} 条记录，如果全部显示需要较长的时间，当前已经抽取 {1} 条记录，请选择要处理的方式。";
        public dlgAskFetch(int nCount,DataSourceBinding dsb,BaseForm frm)
        {
            InitializeComponent();
            RecordCount = nCount;
            string msg = string.Format(Msg, RecordCount, dsb.RecordLimit);
            this.meMsg.Text = msg;
            this.btnOK.Text = string.Format("抽取下{0}", dsb.RecordLimit);
            Dsb = dsb;
            ParentForm = frm;
        }
        /// <summary>
        /// 抽取模式,1抽取下一段,2抽取所有
        /// </summary>
        public int FetchMode
        {
            get;
            set;
        }
        private void btnList_Click(object sender, EventArgs e)
        {
            this.FetchMode = 2;
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.FetchMode = 1;
            if(Dsb != null)
                SalWindow.FireWindowActions(ParentForm, Const.PM_DataSourceRefresh, FetchMode, this.Dsb.Identify);
            string msg = string.Format(Msg, this.Dsb.Session.RecordCount,this.Dsb.Session.RecordPos);
            this.meMsg.Text = msg;
            this.Dsb.ResetBindings(false);
            if (this.Dsb.Session.RecordCount <= this.Dsb.Session.RecordPos)
            {
                btnOK.Enabled = false;
                this.Close();
            }
           // this.DialogResult = System.Windows.Forms.DialogResult.OK;
           // this.Close();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.FetchMode = 0;
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}
